<!doctype html>
<html lang="en" data-color-mode="dark">
<head>
<meta charset="utf-8">
<title>C 备忘清单
 &#x26;  c cheatsheet &#x26;  Quick Reference</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta description="提供基本语法和方法的 C 快速参考备忘单。

入门，为开发人员分享快速参考备忘单。">
<meta keywords="c,reference,Quick,Reference,cheatsheet,cheat,sheet">
<link rel="icon" href="data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20height%3D%221em%22%20width%3D%221em%22%3E%20%3Cpath%20d%3D%22m21.66%2010.44-.98%204.18c-.84%203.61-2.5%205.07-5.62%204.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2%201.17-2.42%203.16-3.07%206.5-2.28l1.67.39c4.19.98%205.47%203.05%204.49%207.23Z%22%20fill%3D%22%23c9d1d9%22%2F%3E%20%3Cpath%20d%3D%22M15.06%2019.39c-.62.42-1.4.77-2.35%201.08l-1.58.52c-3.97%201.28-6.06.21-7.35-3.76L2.5%2013.28c-1.28-3.97-.22-6.07%203.75-7.35l1.58-.52c.41-.13.8-.24%201.17-.31-.3.61-.54%201.35-.74%202.2l-.98%204.19c-.98%204.18.31%206.24%204.48%207.23l1.68.4c.58.14%201.12.23%201.62.27Zm2.43-8.88c-.06%200-.12-.01-.19-.02l-4.85-1.23a.75.75%200%200%201%20.37-1.45l4.85%201.23a.748.748%200%200%201-.18%201.47Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3Cpath%20d%3D%22M14.56%2013.89c-.06%200-.12-.01-.19-.02l-2.91-.74a.75.75%200%200%201%20.37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3C%2Fsvg%3E" type="image/svg+xml">
<link rel="stylesheet" href="../style/style.css">
<link rel="stylesheet" href="../style/katex.css">
</head>
<body><nav class="header-nav"><div class="max-container"><a href="../index.html" class="logo"><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
  <path d="m21.66 10.44-.98 4.18c-.84 3.61-2.5 5.07-5.62 4.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2 1.17-2.42 3.16-3.07 6.5-2.28l1.67.39c4.19.98 5.47 3.05 4.49 7.23Z" fill="#c9d1d9"></path>
  <path d="M15.06 19.39c-.62.42-1.4.77-2.35 1.08l-1.58.52c-3.97 1.28-6.06.21-7.35-3.76L2.5 13.28c-1.28-3.97-.22-6.07 3.75-7.35l1.58-.52c.41-.13.8-.24 1.17-.31-.3.61-.54 1.35-.74 2.2l-.98 4.19c-.98 4.18.31 6.24 4.48 7.23l1.68.4c.58.14 1.12.23 1.62.27Zm2.43-8.88c-.06 0-.12-.01-.19-.02l-4.85-1.23a.75.75 0 0 1 .37-1.45l4.85 1.23a.748.748 0 0 1-.18 1.47Z" fill="#228e6c"></path>
  <path d="M14.56 13.89c-.06 0-.12-.01-.19-.02l-2.91-.74a.75.75 0 0 1 .37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z" fill="#228e6c"></path>
</svg>
<span class="title">Quick Reference</span></a><div class="menu"><a href="javascript:void(0);" class="searchbtn" id="searchbtn"><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><span>搜索</span><span>⌘K</span></a><a href="https://github.com/jaywcjlove/reference/blob/main/docs/c.md" class="" target="__blank"><svg viewBox="0 0 36 36" fill="currentColor" height="1em" width="1em"><path d="m33 6.4-3.7-3.7a1.71 1.71 0 0 0-2.36 0L23.65 6H6a2 2 0 0 0-2 2v22a2 2 0 0 0 2 2h22a2 2 0 0 0 2-2V11.76l3-3a1.67 1.67 0 0 0 0-2.36ZM18.83 20.13l-4.19.93 1-4.15 9.55-9.57 3.23 3.23ZM29.5 9.43 26.27 6.2l1.85-1.85 3.23 3.23Z"></path><path fill="none" d="M0 0h36v36H0z"></path></svg><span>编辑</span></a><button id="darkMode" type="button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="light" height="1em" width="1em">
  <path d="M6.995 12c0 2.761 2.246 5.007 5.007 5.007s5.007-2.246 5.007-5.007-2.246-5.007-5.007-5.007S6.995 9.239 6.995 12zM11 19h2v3h-2zm0-17h2v3h-2zm-9 9h3v2H2zm17 0h3v2h-3zM5.637 19.778l-1.414-1.414 2.121-2.121 1.414 1.414zM16.242 6.344l2.122-2.122 1.414 1.414-2.122 2.122zM6.344 7.759 4.223 5.637l1.415-1.414 2.12 2.122zm13.434 10.605-1.414 1.414-2.122-2.122 1.414-1.414z"></path>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" class="dark" height="1em" width="1em">
  <path d="M12 11.807A9.002 9.002 0 0 1 10.049 2a9.942 9.942 0 0 0-5.12 2.735c-3.905 3.905-3.905 10.237 0 14.142 3.906 3.906 10.237 3.905 14.143 0a9.946 9.946 0 0 0 2.735-5.119A9.003 9.003 0 0 1 12 11.807z"></path>
</svg>
</button><script src="../js/dark.js"></script><a href="https://github.com/jaywcjlove/reference" class="" target="__blank"><svg viewBox="0 0 16 16" fill="currentColor" height="1em" width="1em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg></a></div></div></nav><div class="wrap h1body-exist max-container"><header class="wrap-header h1wrap"><h1 id="c-备忘清单"><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 38 42">
<path fill="currentColor" fill-rule="evenodd" d="M20.096,0.28575 C21.6507561,1.15835976 24.653163,2.84381008 27.7615951,4.58873655 L28.7451648,5.14086432 C32.0250464,6.98202246 35.2659268,8.80121341 36.903,9.71975 C37.582,10.09975 38,10.80375 38,11.56575 L38,30.43275 C38,31.19475 37.582,31.89875 36.903,32.27975 C35.3482439,33.1523598 32.345837,34.8378101 29.2374049,36.5827365 L28.2538352,37.1348643 C24.9739536,38.9760225 21.7330732,40.7952134 20.096,41.71375 C19.417,42.09475 18.581,42.09475 17.903,41.71375 C16.3482439,40.8411402 13.345837,39.1556899 10.2374049,37.4107635 L9.2538352,36.8586357 C5.9739536,35.0174775 2.73307317,33.1982866 1.096,32.27975 C0.418,31.89875 0,31.19575 0,30.43375 L0,11.56675 C0,10.80475 0.418,10.10075 1.097,9.71975 C4.451,7.83675 14.549,2.16875 17.903,0.28575 C18.582,-0.09525 19.418,-0.09525 20.096,0.28575 Z M19,6.99975 C11.273,6.99975 5,13.27275 5,20.99975 C5,28.72675 11.273,34.99975 19,34.99975 C24.2106279,34.99975 28.7600712,32.1471979 31.1706024,27.9198213 L25.0359394,24.544542 C23.8185152,26.6113911 21.5699125,27.99975 19,27.99975 C15.137,27.99975 12,24.86275 12,20.99975 C12,17.13575 15.136,13.99975 19,13.99975 C21.527968,13.99975 23.7450291,15.3427307 24.9755084,17.353858 L31.0544381,13.8798146 C28.6157645,9.76264004 24.1280833,6.99975 19,6.99975 Z"></path>
</svg><a aria-hidden="true" tabindex="-1" href="#c-备忘清单"><span class="icon icon-link"></span></a>C 备忘清单</h1><div class="wrap-body">
<p>提供基本语法和方法的 C 快速参考备忘单。</p>
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
  <path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#helloc">hello.c</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#变量">变量</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#常量-constants">常量 Constants</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#注释">注释</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#打印文本">打印文本</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#控制空格数">控制空格数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#字符串-strings">字符串 Strings</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#条件判断">条件判断</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#三元运算符">三元运算符</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#switch">Switch</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#while-循环">While 循环</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#dowhile-循环">Do/While 循环</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#for-循环">For 循环</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#跳出循环-breakcontinue">跳出循环 Break/Continue</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#while-break-示例">While Break 示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#while-continue-示例">While continue 示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#数组-arrays">数组 Arrays</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#枚举-enum">枚举 Enum</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#枚举示例应用">枚举示例应用</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#用户输入">用户输入</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#用户输入字符串">用户输入字符串</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#内存地址">内存地址</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建指针">创建指针</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#指针变量">指针变量</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#取消引用">取消引用</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#运算符">运算符</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#算术运算符">算术运算符</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#赋值运算符">赋值运算符</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#比较运算符">比较运算符</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#逻辑运算符">逻辑运算符</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#运算符示例">运算符示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#位运算符">位运算符</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#数据类型-data-types">数据类型 Data Types</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#基本数据类型">基本数据类型</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#数据类型">数据类型</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#基本格式说明符">基本格式说明符</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#基本格式说明符-1">基本格式说明符</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#数据格式示例">数据格式示例</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#预处理器">预处理器</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#预处理器指令">预处理器指令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#预定义宏">预定义宏</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#预定义宏示例">预定义宏示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#宏延续运算符">宏延续运算符（\）</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#字符串常量化运算符">字符串常量化运算符（#）</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#标记粘贴运算符">标记粘贴运算符（##）</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#defined-运算符">defined() 运算符</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#参数化的宏">参数化的宏</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#函数">函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#函数声明和定义">函数声明和定义</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#调用函数">调用函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#函数参数">函数参数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#多个参数">多个参数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#返回值">返回值</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#递归示例">递归示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#数学函数">数学函数</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#structures-结构">Structures 结构</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建结构">创建结构</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#结构中的字符串">结构中的字符串</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#访问结构成员">访问结构成员</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#复制结构">复制结构</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#修改值">修改值</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#文件处理">文件处理</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#文件处理函数">文件处理函数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#打开模式参数">打开模式参数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#打开文件fopen">打开文件：fopen()</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#写入文件fprintf">写入文件：fprintf()</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#读取文件fscanf">读取文件：fscanf()</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#写入文件fputc">写入文件：fputc()</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#读取文件fgetc">读取文件：fgetc()</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#写入文件fputs">写入文件：fputs()</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#读取文件fgets">读取文件：fgets()</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#fseek">fseek()</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#rewind">rewind()</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#ftell">ftell()</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#杂项">杂项</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-运行环境">Docker 运行环境</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="helloc"><a aria-hidden="true" tabindex="-1" href="#helloc"><span class="icon icon-link"></span></a>hello.c</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Hello World!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>使用 <code>gcc</code> 编译 <code>hello.c</code> 文件</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ gcc <span class="token parameter variable">-o</span> hello hello.c
</span></code></pre>
<p>运行编译后的二进制文件(<code>hello</code>)</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ ./hello
</span><span class="code-line"><span class="token comment"># 输出 => Hello World</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="变量"><a aria-hidden="true" tabindex="-1" href="#变量"><span class="icon icon-link"></span></a>变量</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> myNum <span class="token operator">=</span> <span class="token number">15</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> myNum2<span class="token punctuation">;</span> <span class="token comment">// 不赋值，然后再赋值</span>
</span><span class="code-line">myNum2 <span class="token operator">=</span> <span class="token number">15</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> myNum3 <span class="token operator">=</span> <span class="token number">15</span><span class="token punctuation">;</span>  <span class="token comment">// myNum3 值为 15</span>
</span><span class="code-line">myNum3 <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>      <span class="token comment">// 现在 myNum3 值为 10</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">float</span> myFloatNum <span class="token operator">=</span> <span class="token number">5.99</span><span class="token punctuation">;</span> <span class="token comment">// 浮点数</span>
</span><span class="code-line"><span class="token keyword">char</span> myLetter <span class="token operator">=</span> <span class="token char">'D'</span><span class="token punctuation">;</span>     <span class="token comment">// 字符</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> x <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">int</span> y <span class="token operator">=</span> <span class="token number">6</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">int</span> sum <span class="token operator">=</span> x <span class="token operator">+</span> y<span class="token punctuation">;</span>  <span class="token comment">// 添加变量相加</span>
</span><span class="code-line"><span class="token comment">// 声明多个变量</span>
</span><span class="code-line"><span class="token keyword">int</span> x <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">,</span> y <span class="token operator">=</span> <span class="token number">6</span><span class="token punctuation">,</span> z <span class="token operator">=</span> <span class="token number">50</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="常量-constants"><a aria-hidden="true" tabindex="-1" href="#常量-constants"><span class="icon icon-link"></span></a>常量 Constants</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">const</span> <span class="token keyword">int</span> minutesPerHour <span class="token operator">=</span> <span class="token number">60</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">const</span> <span class="token keyword">float</span> PI <span class="token operator">=</span> <span class="token number">3.14</span><span class="token punctuation">;</span>
</span></code></pre>
<p>最佳实践</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">const</span> <span class="token keyword">int</span> BIRTHYEAR <span class="token operator">=</span> <span class="token number">1980</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="注释"><a aria-hidden="true" tabindex="-1" href="#注释"><span class="icon icon-link"></span></a>注释</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token comment">// 这是一个注释</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Hello World!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 这是一个注释</span>
</span><span class="code-line"><span class="token comment">/* 多行注释，上面的代码将打印出 Hello World!
</span></span><span class="code-line"><span class="token comment">到屏幕上，真是太棒了 */</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="打印文本"><a aria-hidden="true" tabindex="-1" href="#打印文本"><span class="icon icon-link"></span></a>打印文本</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"I am learning C."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">int</span> testInteger <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Number = %d"</span><span class="token punctuation">,</span> testInteger<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">float</span> f <span class="token operator">=</span> <span class="token number">5.99</span><span class="token punctuation">;</span> <span class="token comment">// 浮点数</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Value = %f"</span><span class="token punctuation">,</span> f<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">short</span> a <span class="token operator">=</span> <span class="token number">0</span>b1010110<span class="token punctuation">;</span>  <span class="token comment">// 2 进制数字</span>
</span><span class="code-line"><span class="token keyword">int</span> b <span class="token operator">=</span> <span class="token number">02713</span><span class="token punctuation">;</span>        <span class="token comment">// 8 进制数字</span>
</span><span class="code-line"><span class="token keyword">long</span> c <span class="token operator">=</span> <span class="token number">0X1DAB83</span><span class="token punctuation">;</span>    <span class="token comment">// 16 进制数字</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token comment">// 以 8 进制形似输出</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"a=%ho, b=%o, c=%lo\n"</span><span class="token punctuation">,</span> a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 输出 => a=126, b=2713, c=7325603</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token comment">// 以 10 进制形式输出</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"a=%hd, b=%d, c=%ld\n"</span><span class="token punctuation">,</span> a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 输出 => a=86, b=1483, c=1944451</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token comment">// 以 16 进制形式输出（字母小写）</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"a=%hx, b=%x, c=%lx\n"</span><span class="token punctuation">,</span> a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 输出 => a=56, b=5cb, c=1dab83</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token comment">// 以 16 进制形式输出（字母大写）</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"a=%hX, b=%X, c=%lX\n"</span><span class="token punctuation">,</span> a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 输出 => a=56, b=5CB, c=1DAB83</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="控制空格数"><a aria-hidden="true" tabindex="-1" href="#控制空格数"><span class="icon icon-link"></span></a>控制空格数</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> a1<span class="token operator">=</span><span class="token number">20</span><span class="token punctuation">,</span> a2<span class="token operator">=</span><span class="token number">345</span><span class="token punctuation">,</span> a3<span class="token operator">=</span><span class="token number">700</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">int</span> b1<span class="token operator">=</span><span class="token number">56720</span><span class="token punctuation">,</span> b2<span class="token operator">=</span><span class="token number">9999</span><span class="token punctuation">,</span> b3<span class="token operator">=</span><span class="token number">20098</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">int</span> c1<span class="token operator">=</span><span class="token number">233</span><span class="token punctuation">,</span> c2<span class="token operator">=</span><span class="token number">205</span><span class="token punctuation">,</span> c3<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">int</span> d1<span class="token operator">=</span><span class="token number">34</span><span class="token punctuation">,</span> d2<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">,</span> d3<span class="token operator">=</span><span class="token number">23</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%-9d %-9d %-9d\n"</span><span class="token punctuation">,</span> a1<span class="token punctuation">,</span> a2<span class="token punctuation">,</span> a3<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%-9d %-9d %-9d\n"</span><span class="token punctuation">,</span> b1<span class="token punctuation">,</span> b2<span class="token punctuation">,</span> b3<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%-9d %-9d %-9d\n"</span><span class="token punctuation">,</span> c1<span class="token punctuation">,</span> c2<span class="token punctuation">,</span> c3<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%-9d %-9d %-9d\n"</span><span class="token punctuation">,</span> d1<span class="token punctuation">,</span> d2<span class="token punctuation">,</span> d3<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
<p>输出结果</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token number">20</span>        <span class="token number">345</span>       <span class="token number">700</span>  
</span><span class="code-line"><span class="token number">56720</span>     <span class="token number">9999</span>      <span class="token number">20098</span>
</span><span class="code-line"><span class="token number">233</span>       <span class="token number">205</span>       <span class="token number">1</span>    
</span><span class="code-line"><span class="token number">34</span>        <span class="token number">0</span>         <span class="token number">23</span>   
</span></code></pre>
<p><code>%-9d</code> 中，<code>d</code> 表示以 <code>10</code> 进制输出，<code>9</code> 表示最少占 <code>9</code> 个字符的宽度，宽度不足以空格补齐，<code>-</code> 表示左对齐</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="字符串-strings"><a aria-hidden="true" tabindex="-1" href="#字符串-strings"><span class="icon icon-link"></span></a>字符串 Strings</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">char</span> greetings<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">"Hello World!"</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%s"</span><span class="token punctuation">,</span> greetings<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
<p>访问字符串</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">char</span> greetings<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">"Hello World!"</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%c"</span><span class="token punctuation">,</span> greetings<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
<p>修改字符串</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">char</span> greetings<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">"Hello World!"</span><span class="token punctuation">;</span>
</span><span class="code-line">greetings<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token char">'J'</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%s"</span><span class="token punctuation">,</span> greetings<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 输出 "Jello World!"</span>
</span></code></pre>
<p>另一种创建字符串的方法</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">char</span> greetings<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token char">'H'</span><span class="token punctuation">,</span><span class="token char">'e'</span><span class="token punctuation">,</span><span class="token char">'l'</span><span class="token punctuation">,</span><span class="token char">'l'</span><span class="token punctuation">,</span><span class="token char">'\0'</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%s"</span><span class="token punctuation">,</span> greetings<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 输出 "Hell!"</span>
</span></code></pre>
<p><code>C</code> <strong>没有</strong> String 类型，使用 <code>char</code> 类型并创建一个字符 <code>array</code></p>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="条件判断"><a aria-hidden="true" tabindex="-1" href="#条件判断"><span class="icon icon-link"></span></a>条件判断</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> time <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">if</span> <span class="token punctuation">(</span>time <span class="token operator">&#x3C;</span> <span class="token number">18</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"再会！"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"晚上好！"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token comment">// 输出 -> "晚上好！"</span>
</span><span class="code-line"><span class="token keyword">int</span> time <span class="token operator">=</span> <span class="token number">22</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">if</span> <span class="token punctuation">(</span>time <span class="token operator">&#x3C;</span> <span class="token number">10</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"早上好！"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>time <span class="token operator">&#x3C;</span> <span class="token number">20</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"再会！"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"晚上好！"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token comment">// 输出 -> "晚上好！"</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="三元运算符"><a aria-hidden="true" tabindex="-1" href="#三元运算符"><span class="icon icon-link"></span></a>三元运算符</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> time <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">(</span>time <span class="token operator">&#x3C;</span> <span class="token number">18</span><span class="token punctuation">)</span> <span class="token operator">?</span> <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"再会！"</span><span class="token punctuation">)</span> <span class="token operator">:</span> <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"晚上好！"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="switch"><a aria-hidden="true" tabindex="-1" href="#switch"><span class="icon icon-link"></span></a>Switch</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> day <span class="token operator">=</span> <span class="token number">4</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">switch</span> <span class="token punctuation">(</span>day<span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">case</span> <span class="token number">3</span><span class="token operator">:</span> <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"周三"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">break</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">case</span> <span class="token number">4</span><span class="token operator">:</span> <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"周四"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">break</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">default</span><span class="token operator">:</span>
</span><span class="code-line">    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"期待周末"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token comment">// 输出 -> "周四" (day 4)</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="while-循环"><a aria-hidden="true" tabindex="-1" href="#while-循环"><span class="icon icon-link"></span></a>While 循环</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">while</span> <span class="token punctuation">(</span>i <span class="token operator">&#x3C;</span> <span class="token number">5</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  i<span class="token operator">++</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p><strong>注意</strong>：不要忘记增加条件中使用的变量，否则循环永远不会结束，成为“死循环”！</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="dowhile-循环"><a aria-hidden="true" tabindex="-1" href="#dowhile-循环"><span class="icon icon-link"></span></a>Do/While 循环</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">do</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  i<span class="token operator">++</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span> <span class="token keyword">while</span> <span class="token punctuation">(</span>i <span class="token operator">&#x3C;</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="for-循环"><a aria-hidden="true" tabindex="-1" href="#for-循环"><span class="icon icon-link"></span></a>For 循环</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> i<span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">for</span> <span class="token punctuation">(</span>i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&#x3C;</span> <span class="token number">5</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="跳出循环-breakcontinue"><a aria-hidden="true" tabindex="-1" href="#跳出循环-breakcontinue"><span class="icon icon-link"></span></a>跳出循环 Break/Continue</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> i<span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">for</span> <span class="token punctuation">(</span>i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&#x3C;</span> <span class="token number">10</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">if</span> <span class="token punctuation">(</span>i <span class="token operator">==</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token keyword">break</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>在 <code>i</code> 等于 <code>4</code> 时跳出循环</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> i<span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">for</span> <span class="token punctuation">(</span>i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&#x3C;</span> <span class="token number">10</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">if</span> <span class="token punctuation">(</span>i <span class="token operator">==</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token keyword">continue</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>示例跳过 <code>4</code> 的值</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="while-break-示例"><a aria-hidden="true" tabindex="-1" href="#while-break-示例"><span class="icon icon-link"></span></a>While Break 示例</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">while</span> <span class="token punctuation">(</span>i <span class="token operator">&#x3C;</span> <span class="token number">10</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">if</span> <span class="token punctuation">(</span>i <span class="token operator">==</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token keyword">break</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  i<span class="token operator">++</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="while-continue-示例"><a aria-hidden="true" tabindex="-1" href="#while-continue-示例"><span class="icon icon-link"></span></a>While continue 示例</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">while</span> <span class="token punctuation">(</span>i <span class="token operator">&#x3C;</span> <span class="token number">10</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  i<span class="token operator">++</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">if</span> <span class="token punctuation">(</span>i <span class="token operator">==</span> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token keyword">continue</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> i<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="数组-arrays"><a aria-hidden="true" tabindex="-1" href="#数组-arrays"><span class="icon icon-link"></span></a>数组 Arrays</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> myNumbers<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">25</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d"</span><span class="token punctuation">,</span> myNumbers<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 输出 25</span>
</span></code></pre>
<p>更改数组元素</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> myNumbers<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">25</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="code-line">myNumbers<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">33</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d"</span><span class="token punctuation">,</span> myNumbers<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
<p>循环遍历数组</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> myNumbers<span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">25</span><span class="token punctuation">,</span> <span class="token number">50</span><span class="token punctuation">,</span> <span class="token number">75</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">int</span> i<span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">for</span> <span class="token punctuation">(</span>i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&#x3C;</span> <span class="token number">4</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> myNumbers<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>设置数组大小</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token comment">// 声明一个由四个整数组成的数组：</span>
</span><span class="code-line"><span class="token keyword">int</span> myNumbers<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 添加元素</span>
</span><span class="code-line">myNumbers<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">25</span><span class="token punctuation">;</span>
</span><span class="code-line">myNumbers<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">50</span><span class="token punctuation">;</span>
</span><span class="code-line">myNumbers<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">75</span><span class="token punctuation">;</span>
</span><span class="code-line">myNumbers<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token number">100</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="枚举-enum"><a aria-hidden="true" tabindex="-1" href="#枚举-enum"><span class="icon icon-link"></span></a>枚举 Enum</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">enum</span> <span class="token class-name">week</span> <span class="token punctuation">{</span> Mon <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> Tues<span class="token punctuation">,</span> Wed<span class="token punctuation">,</span> Thurs<span class="token punctuation">,</span> Fri<span class="token punctuation">,</span> Sat<span class="token punctuation">,</span> Sun <span class="token punctuation">}</span><span class="token punctuation">;</span>
</span></code></pre>
<p>定义枚举变量</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">enum</span> <span class="token class-name">week</span> a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c<span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">enum</span> <span class="token class-name">week</span> <span class="token punctuation">{</span> Mon <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> Tues<span class="token punctuation">,</span> Wed<span class="token punctuation">,</span> Thurs<span class="token punctuation">,</span> Fri<span class="token punctuation">,</span> Sat<span class="token punctuation">,</span> Sun <span class="token punctuation">}</span> a<span class="token punctuation">,</span> b<span class="token punctuation">,</span> c<span class="token punctuation">;</span>
</span></code></pre>
<p>有了枚举变量，就可以把列表中的值赋给它</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">enum</span> <span class="token class-name">week</span> <span class="token punctuation">{</span> Mon <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> Tues<span class="token punctuation">,</span> Wed<span class="token punctuation">,</span> Thurs<span class="token punctuation">,</span> Fri<span class="token punctuation">,</span> Sat<span class="token punctuation">,</span> Sun <span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">enum</span> <span class="token class-name">week</span> a <span class="token operator">=</span> Mon<span class="token punctuation">,</span> b <span class="token operator">=</span> Wed<span class="token punctuation">,</span> c <span class="token operator">=</span> Sat<span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 或者</span>
</span><span class="code-line"><span class="token keyword">enum</span> <span class="token class-name">week</span><span class="token punctuation">{</span> Mon <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> Tues<span class="token punctuation">,</span> Wed<span class="token punctuation">,</span> Thurs<span class="token punctuation">,</span> Fri<span class="token punctuation">,</span> Sat<span class="token punctuation">,</span> Sun <span class="token punctuation">}</span> a <span class="token operator">=</span> Mon<span class="token punctuation">,</span> b <span class="token operator">=</span> Wed<span class="token punctuation">,</span> c <span class="token operator">=</span> Sat<span class="token punctuation">;</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="枚举示例应用"><a aria-hidden="true" tabindex="-1" href="#枚举示例应用"><span class="icon icon-link"></span></a>枚举示例应用</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">enum</span> <span class="token class-name">week</span> <span class="token punctuation">{</span>Mon <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span> Tues<span class="token punctuation">,</span> Wed<span class="token punctuation">,</span> Thurs<span class="token punctuation">}</span> day<span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">"%d"</span><span class="token punctuation">,</span> <span class="token operator">&#x26;</span>day<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">switch</span><span class="token punctuation">(</span>day<span class="token punctuation">)</span><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">case</span> Mon<span class="token operator">:</span>   <span class="token function">puts</span><span class="token punctuation">(</span><span class="token string">"Monday"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">break</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">case</span> Tues<span class="token operator">:</span>  <span class="token function">puts</span><span class="token punctuation">(</span><span class="token string">"Tuesday"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">break</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">case</span> Wed<span class="token operator">:</span>   <span class="token function">puts</span><span class="token punctuation">(</span><span class="token string">"Wednesday"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">break</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">case</span> Thurs<span class="token operator">:</span> <span class="token function">puts</span><span class="token punctuation">(</span><span class="token string">"Thursday"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">break</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">default</span><span class="token operator">:</span>    <span class="token function">puts</span><span class="token punctuation">(</span><span class="token string">"Error!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="用户输入"><a aria-hidden="true" tabindex="-1" href="#用户输入"><span class="icon icon-link"></span></a>用户输入</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token comment">// 创建一个整数变量来存储我们从用户那里得到的数字</span>
</span><span class="code-line"><span class="token keyword">int</span> myNum<span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token comment">// 要求用户输入一个数字</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"请输入一个数字: \n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token comment">// 获取并保存用户输入的号码</span>
</span><span class="code-line"><span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">"%d"</span><span class="token punctuation">,</span> <span class="token operator">&#x26;</span>myNum<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token comment">// 输出用户输入的数字</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"您输入的数字: %d"</span><span class="token punctuation">,</span> myNum<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="用户输入字符串"><a aria-hidden="true" tabindex="-1" href="#用户输入字符串"><span class="icon icon-link"></span></a>用户输入字符串</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token comment">// 创建一个字符串</span>
</span><span class="code-line"><span class="token keyword">char</span> firstName<span class="token punctuation">[</span><span class="token number">30</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 要求用户输入一些文本</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"输入您的名字: \n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 获取并保存文本</span>
</span><span class="code-line"><span class="token function">scanf</span><span class="token punctuation">(</span><span class="token string">"%s"</span><span class="token punctuation">,</span> firstName<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 输出文本</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Hello %s."</span><span class="token punctuation">,</span> firstName<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="内存地址"><a aria-hidden="true" tabindex="-1" href="#内存地址"><span class="icon icon-link"></span></a>内存地址</h3><div class="wrap-body">
<p>创建变量时，会为该变量分配一个内存地址</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> myAge <span class="token operator">=</span> <span class="token number">43</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%p"</span><span class="token punctuation">,</span> <span class="token operator">&#x26;</span>myAge<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 输出：0x7ffe5367e044</span>
</span></code></pre>
<p>要访问它，请使用引用运算符 (<code>&#x26;</code>)</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="创建指针"><a aria-hidden="true" tabindex="-1" href="#创建指针"><span class="icon icon-link"></span></a>创建指针</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> myAge <span class="token operator">=</span> <span class="token number">43</span><span class="token punctuation">;</span>      <span class="token comment">// 一个 int 变量</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d"</span><span class="token punctuation">,</span> myAge<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 输出 myAge(43)的值</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token comment">// 输出 myAge 的内存地址（0x7ffe5367e044）</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%p"</span><span class="token punctuation">,</span> <span class="token operator">&#x26;</span>myAge<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="指针变量"><a aria-hidden="true" tabindex="-1" href="#指针变量"><span class="icon icon-link"></span></a>指针变量</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> myAge <span class="token operator">=</span> <span class="token number">43</span><span class="token punctuation">;</span>            <span class="token comment">// 一个 int 变量</span>
</span><span class="code-line"><span class="token keyword">int</span><span class="token operator">*</span> ptr <span class="token operator">=</span> <span class="token operator">&#x26;</span>myAge<span class="token punctuation">;</span>         <span class="token comment">// 名为 ptr 的指针变量，用于存储 myAge 的地址</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> myAge<span class="token punctuation">)</span><span class="token punctuation">;</span>     <span class="token comment">// 输出 myAge (43) 的值</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%p\n"</span><span class="token punctuation">,</span> \<span class="token operator">&#x26;</span>myAge<span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">// 输出 myAge 的内存地址（0x7ffe5367e044）</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%p\n"</span><span class="token punctuation">,</span> ptr<span class="token punctuation">)</span><span class="token punctuation">;</span>       <span class="token comment">// 用指针（0x7ffe5367e044）输出myAge的内存地址</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="取消引用"><a aria-hidden="true" tabindex="-1" href="#取消引用"><span class="icon icon-link"></span></a>取消引用</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> myAge <span class="token operator">=</span> <span class="token number">43</span><span class="token punctuation">;</span>     <span class="token comment">// 变量声明</span>
</span><span class="code-line"><span class="token keyword">int</span><span class="token operator">*</span> ptr <span class="token operator">=</span> <span class="token operator">&#x26;</span>myAge<span class="token punctuation">;</span>  <span class="token comment">// 指针声明</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token comment">// 参考：用指针输出 myAge 的</span>
</span><span class="code-line"><span class="token comment">// 内存地址（0x7ffe5367e044）</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%p\n"</span><span class="token punctuation">,</span> ptr<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 取消引用：用指针输出 myAge 的值 (43)</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> <span class="token operator">*</span>ptr<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="运算符"><a aria-hidden="true" tabindex="-1" href="#运算符"><span class="icon icon-link"></span></a>运算符</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="算术运算符"><a aria-hidden="true" tabindex="-1" href="#算术运算符"><span class="icon icon-link"></span></a>算术运算符</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> myNum <span class="token operator">=</span> <span class="token number">100</span> <span class="token operator">+</span> <span class="token number">50</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">int</span> sum1 <span class="token operator">=</span> <span class="token number">100</span> <span class="token operator">+</span> <span class="token number">50</span><span class="token punctuation">;</span>    <span class="token comment">// 150 (100 + 50)</span>
</span><span class="code-line"><span class="token keyword">int</span> sum2 <span class="token operator">=</span> sum1 <span class="token operator">+</span> <span class="token number">250</span><span class="token punctuation">;</span>  <span class="token comment">// 400 (150 + 250)</span>
</span><span class="code-line"><span class="token keyword">int</span> sum3 <span class="token operator">=</span> sum2 <span class="token operator">+</span> sum2<span class="token punctuation">;</span> <span class="token comment">// 800 (400 + 400)</span>
</span></code></pre>
<hr>





















































<table><thead><tr><th>Operator</th><th>Name</th><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>+</code></td><td>加</td><td>将两个值相加</td><td><code>x + y</code></td></tr><tr><td><code>-</code></td><td>减</td><td>从另一个值中减去一个值</td><td><code>x - y</code></td></tr><tr><td><code>*</code></td><td>乘</td><td>将两个值相乘</td><td><code>x * y</code></td></tr><tr><td><code>/</code></td><td>除</td><td>将一个值除以另一个</td><td><code>x / y</code></td></tr><tr><td><code>%</code></td><td>取模</td><td>返回除法余数</td><td><code>x % y</code></td></tr><tr><td><code>++</code></td><td>增量</td><td>将变量的值增加 1</td><td><code>++</code></td></tr><tr><td><code>--</code></td><td>乘量</td><td>将变量的值减 1</td><td><code>--x</code></td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="赋值运算符"><a aria-hidden="true" tabindex="-1" href="#赋值运算符"><span class="icon icon-link"></span></a>赋值运算符</h3><div class="wrap-body">

































































<table><thead><tr><th>符号</th><th>示例</th><th>如同</th></tr></thead><tbody><tr><td><code>=</code></td><td>x <code>=</code> 5</td><td>x <code>=</code> 5</td></tr><tr><td><code>+=</code></td><td>x <code>+=</code> 3</td><td>x <code>=</code> x <code>+</code> 3</td></tr><tr><td><code>-=</code></td><td>x <code>-=</code> 3</td><td>x <code>=</code> x <code>-</code> 3</td></tr><tr><td><code>*=</code></td><td>x <code>*=</code> 3</td><td>x <code>=</code> x <code>*</code> 3</td></tr><tr><td><code>/=</code></td><td>x <code>/=</code> 3</td><td>x <code>=</code> x <code>/</code> 3</td></tr><tr><td><code>%=</code></td><td>x <code>%=</code> 3</td><td>x <code>=</code> x <code>%</code> 3</td></tr><tr><td><code>&#x26;=</code></td><td>x <code>&#x26;=</code> 3</td><td>x <code>=</code> x <code>&#x26;</code> 3</td></tr><tr><td><code>|=</code></td><td>x <code>|=</code> 3</td><td>x <code>=</code> x <code>|</code> 3</td></tr><tr><td><code>^=</code></td><td>x <code>^=</code> 3</td><td>x <code>=</code> x <code>^</code> 3</td></tr><tr><td><code>>>=</code></td><td>x <code>>>=</code> 3</td><td>x <code>=</code> x <code>>></code> 3</td></tr><tr><td><code>&#x3C;&#x3C;=</code></td><td>x <code>&#x3C;&#x3C;=</code> 3</td><td>x <code>=</code> x <code>&#x3C;&#x3C;</code> 3</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="比较运算符"><a aria-hidden="true" tabindex="-1" href="#比较运算符"><span class="icon icon-link"></span></a>比较运算符</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> x <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">int</span> y <span class="token operator">=</span> <span class="token number">3</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d"</span><span class="token punctuation">,</span> x <span class="token operator">></span> y<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 返回 1（真），因为 5 大于 3</span>
</span></code></pre>
<hr>








































<table><thead><tr><th>符号</th><th>名称</th><th>示例</th></tr></thead><tbody><tr><td><code>==</code></td><td>等于</td><td>x <code>==</code> y</td></tr><tr><td><code>!=</code></td><td>不等于</td><td>x <code>!=</code> y</td></tr><tr><td><code>></code></td><td>大于</td><td>x <code>></code> y</td></tr><tr><td><code>&#x3C;</code></td><td>小于</td><td>x <code>&#x3C;</code> y</td></tr><tr><td><code>>=</code></td><td>大于或等于</td><td>x <code>>=</code> y</td></tr><tr><td><code>&#x3C;=</code></td><td>小于或等于</td><td>x <code>&#x3C;=</code> y</td></tr></tbody></table>
<p>比较运算符用于比较两个值</p>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="逻辑运算符"><a aria-hidden="true" tabindex="-1" href="#逻辑运算符"><span class="icon icon-link"></span></a>逻辑运算符</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->





























<table><thead><tr><th>符号</th><th>名称</th><th>说明</th><th>示例</th></tr></thead><tbody><tr><td><code>&#x26;&#x26;</code></td><td><code>与</code>逻辑</td><td>如果两个语句都为真，则返回真</td><td><code>x &#x3C; 5 &#x26;&#x26;  x &#x3C; 10</code></td></tr><tr><td><code>||</code></td><td><code>或</code>逻辑</td><td>如果其中一个语句为真，则返回真</td><td><code>x &#x3C; 5 || x &#x3C; 4</code></td></tr><tr><td><code>!</code></td><td><code>非</code>逻辑</td><td>反转结果，如果结果为真则返回假</td><td><code>!(x &#x3C; 5 &#x26;&#x26; x &#x3C; 10)</code></td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="运算符示例"><a aria-hidden="true" tabindex="-1" href="#运算符示例"><span class="icon icon-link"></span></a>运算符示例</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">unsigned</span> <span class="token keyword">int</span> a <span class="token operator">=</span> <span class="token number">60</span><span class="token punctuation">;</span> <span class="token comment">/* 60 = 0011 1100 */</span>  
</span><span class="code-line"><span class="token keyword">unsigned</span> <span class="token keyword">int</span> b <span class="token operator">=</span> <span class="token number">13</span><span class="token punctuation">;</span> <span class="token comment">/* 13 = 0000 1101 */</span>
</span><span class="code-line"><span class="token keyword">int</span> c <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>           
</span><span class="code-line">
</span><span class="code-line">c <span class="token operator">=</span> a <span class="token operator">&#x26;</span> b<span class="token punctuation">;</span>      <span class="token comment">/* 12 = 0000 1100 */</span> 
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Line 1 - c 的值是 %d\n"</span><span class="token punctuation">,</span> c <span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line">c <span class="token operator">=</span> a <span class="token operator">|</span> b<span class="token punctuation">;</span>      <span class="token comment">/* 61 = 0011 1101 */</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Line 2 - c 的值是 %d\n"</span><span class="token punctuation">,</span> c <span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">c <span class="token operator">=</span> a <span class="token operator">^</span> b<span class="token punctuation">;</span>      <span class="token comment">/* 49 = 0011 0001 */</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Line 3 - c 的值是 %d\n"</span><span class="token punctuation">,</span> c <span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">c <span class="token operator">=</span> <span class="token operator">~</span>a<span class="token punctuation">;</span>         <span class="token comment">/*-61 = 1100 0011 */</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Line 4 - c 的值是 %d\n"</span><span class="token punctuation">,</span> c <span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">c <span class="token operator">=</span> a <span class="token operator">&#x3C;&#x3C;</span> <span class="token number">2</span><span class="token punctuation">;</span>     <span class="token comment">/* 240 = 1111 0000 */</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Line 5 - c 的值是 %d\n"</span><span class="token punctuation">,</span> c <span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">c <span class="token operator">=</span> a <span class="token operator">>></span> <span class="token number">2</span><span class="token punctuation">;</span>     <span class="token comment">/* 15 = 0000 1111 */</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Line 6 - c 的值是 %d\n"</span><span class="token punctuation">,</span> c <span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="位运算符"><a aria-hidden="true" tabindex="-1" href="#位运算符"><span class="icon icon-link"></span></a>位运算符</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->








































<table><thead><tr><th align="left">运算符</th><th align="left">描述</th><th align="left">实例</th></tr></thead><tbody><tr><td align="left"><code>&#x26;</code></td><td align="left">按位与操作，按二进制位进行"与"运算</td><td align="left"><code>(A &#x26; B)</code> 将得到 <code>12</code> 即为 0000 1100</td></tr><tr><td align="left"><code>|</code></td><td align="left">按位或运算符，按二进制位进行"或"运算</td><td align="left"><code>(A | B)</code> 将得到 <code>61</code> 即为 0011 1101</td></tr><tr><td align="left"><code>^</code></td><td align="left">异或运算符，按二进制位进行"异或"运算</td><td align="left"><code>(A ^ B)</code> 将得到 <code>49</code> 即为 0011 0001</td></tr><tr><td align="left"><code>~</code></td><td align="left">取反运算符，按二进制位进行"取反"运算</td><td align="left"><code>(~A)</code> 将得到 <code>-61</code> 即为 1100 0011</td></tr><tr><td align="left"><code>&#x3C;&#x3C;</code></td><td align="left">二进制左移运算符</td><td align="left"><code>A &#x3C;&#x3C; 2</code> 将得到 <code>240</code> 即为 1111 0000</td></tr><tr><td align="left"><code>>></code></td><td align="left">二进制右移运算符</td><td align="left"><code>A >> 2</code> 将得到 <code>15</code> 即为 0000 1111</td></tr></tbody></table>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="数据类型-data-types"><a aria-hidden="true" tabindex="-1" href="#数据类型-data-types"><span class="icon icon-link"></span></a>数据类型 Data Types</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="基本数据类型"><a aria-hidden="true" tabindex="-1" href="#基本数据类型"><span class="icon icon-link"></span></a>基本数据类型</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->





































































































<table><thead><tr><th>数据类型</th><th>大小 Size</th><th>范围 Range</th><th>描述 Description</th></tr></thead><tbody><tr><td><code>char</code></td><td>1 字节</td><td><code>−128</code> ~ <code>127</code></td><td>单个字符/字母/数字/ASCII</td></tr><tr><td><code>signed char</code></td><td>1 字节</td><td><code>−128</code> ~ <code>127</code></td><td>-</td></tr><tr><td><code>unsigned char</code></td><td>1 字节</td><td><code>0</code> ~ <code>255</code></td><td>-</td></tr><tr><td><code>int</code></td><td><code>2</code> 到 <code>4</code> 字节</td><td><code>−32,768</code> ~ <code>32,767</code></td><td>存储整数</td></tr><tr><td><code>signed int</code></td><td>2 字节</td><td><code>−32,768</code> ~ <code>32,767</code></td><td></td></tr><tr><td><code>unsigned int</code></td><td>2 字节</td><td><code>0</code> ~ <code>65,535</code></td><td></td></tr><tr><td><code>short int</code></td><td>2 字节</td><td><code>−32,768</code> ~ <code>32,767</code></td><td></td></tr><tr><td><code>signed short int</code></td><td>2 字节</td><td><code>−32,768</code> ~ <code>32,767</code></td><td></td></tr><tr><td><code>unsigned short int</code></td><td>2 字节</td><td><code>0</code> ~ <code>65,535</code></td><td></td></tr><tr><td><code>long int</code></td><td>4 字节</td><td><code>-2,147,483,648</code> ~ <code>2,147,483,647</code></td><td></td></tr><tr><td><code>signed long int</code></td><td>4 字节</td><td><code>-2,147,483,648</code> ~ <code>2,147,483,647</code></td><td></td></tr><tr><td><code>unsigned long int</code></td><td>4 字节</td><td><code>0</code> ~ <code>4,294,967,295</code></td><td></td></tr><tr><td><code>float</code></td><td>4 字节</td><td></td><td></td></tr><tr><td><code>double</code></td><td>8 字节</td><td></td><td></td></tr><tr><td><code>long double</code></td><td>10 字节</td><td></td><td></td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="数据类型"><a aria-hidden="true" tabindex="-1" href="#数据类型"><span class="icon icon-link"></span></a>数据类型</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token comment">// 创建变量</span>
</span><span class="code-line"><span class="token keyword">int</span> myNum <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>             <span class="token comment">// 整数</span>
</span><span class="code-line"><span class="token keyword">float</span> myFloatNum <span class="token operator">=</span> <span class="token number">5.99</span><span class="token punctuation">;</span>   <span class="token comment">// 浮点数</span>
</span><span class="code-line"><span class="token keyword">char</span> myLetter <span class="token operator">=</span> <span class="token char">'D'</span><span class="token punctuation">;</span>       <span class="token comment">// 字符串</span>
</span><span class="code-line"><span class="token comment">// 高精度浮点数据或数字</span>
</span><span class="code-line"><span class="token keyword">double</span> myDouble <span class="token operator">=</span> <span class="token number">3.2325467</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 打印输出变量</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> myNum<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%f\n"</span><span class="token punctuation">,</span> myFloatNum<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%c\n"</span><span class="token punctuation">,</span> myLetter<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%lf\n"</span><span class="token punctuation">,</span> myDouble<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
<hr>





































<table><thead><tr><th align="left">数据类型</th><th align="left">说  明</th></tr></thead><tbody><tr><td align="left"><code>char</code></td><td align="left">字符型</td></tr><tr><td align="left"><code>short</code></td><td align="left">短整型</td></tr><tr><td align="left"><code>int</code></td><td align="left">整型</td></tr><tr><td align="left"><code>long</code></td><td align="left">长整型</td></tr><tr><td align="left"><code>float</code></td><td align="left">单精度浮点型</td></tr><tr><td align="left"><code>double</code></td><td align="left">双精度浮点型</td></tr><tr><td align="left"><code>void</code></td><td align="left">无类型</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="基本格式说明符"><a aria-hidden="true" tabindex="-1" href="#基本格式说明符"><span class="icon icon-link"></span></a>基本格式说明符</h3><div class="wrap-body">





























<table><thead><tr><th>格式说明符</th><th>数据类型</th></tr></thead><tbody><tr><td><code>%d</code> 或 <code>%i</code></td><td><code>int</code> 整数</td></tr><tr><td><code>%f</code></td><td><code>float</code> 单精度的十进制类型</td></tr><tr><td><code>%lf</code></td><td><code>double</code> 高精度浮点数据或数字</td></tr><tr><td><code>%c</code></td><td><code>char</code> 字符</td></tr><tr><td><code>%s</code></td><td>用于 <code>strings</code> 字符串</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="基本格式说明符-1"><a aria-hidden="true" tabindex="-1" href="#基本格式说明符-1"><span class="icon icon-link"></span></a>基本格式说明符</h3><div class="wrap-body">





























<table><thead><tr><th></th><th>short</th><th>int</th><th>long</th></tr></thead><tbody><tr><td>8 进制</td><td><code>%ho</code></td><td><code>%o</code></td><td><code>%lo</code></td></tr><tr><td>10 进制</td><td><code>%hd</code></td><td><code>%d</code></td><td><code>%ld</code></td></tr><tr><td>16 进制</td><td><code>%hx</code> / <code>%hX</code></td><td><code>%x</code> / <code>%X</code></td><td><code>%lx</code> / <code>%lX</code></td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="数据格式示例"><a aria-hidden="true" tabindex="-1" href="#数据格式示例"><span class="icon icon-link"></span></a>数据格式示例</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> myNum <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">float</span> myFloatNum <span class="token operator">=</span> <span class="token number">5.99</span><span class="token punctuation">;</span> <span class="token comment">// 浮点数</span>
</span><span class="code-line"><span class="token keyword">char</span> myLetter <span class="token operator">=</span> <span class="token char">'D'</span><span class="token punctuation">;</span>     <span class="token comment">// 字符串</span>
</span><span class="code-line"><span class="token comment">// 打印输出变量</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d\n"</span><span class="token punctuation">,</span> myNum<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%f\n"</span><span class="token punctuation">,</span> myFloatNum<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%c\n"</span><span class="token punctuation">,</span> myLetter<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="预处理器"><a aria-hidden="true" tabindex="-1" href="#预处理器"><span class="icon icon-link"></span></a>预处理器</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="预处理器指令"><a aria-hidden="true" tabindex="-1" href="#预处理器指令"><span class="icon icon-link"></span></a>预处理器指令</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->





















































<table><thead><tr><th>指令</th><th>描述</th></tr></thead><tbody><tr><td><code>#define</code></td><td>定义宏</td></tr><tr><td><code>#include</code></td><td>包含一个源代码文件</td></tr><tr><td><code>#undef</code></td><td>取消已定义的宏</td></tr><tr><td><code>#ifdef</code></td><td>如果宏已经定义，则返回真</td></tr><tr><td><code>#ifndef</code></td><td>如果宏没有定义，则返回真</td></tr><tr><td><code>#if</code></td><td>如果给定条件为真，则编译下面代码</td></tr><tr><td><code>#else</code></td><td><code>#if</code> 的替代方案</td></tr><tr><td><code>#elif</code></td><td>如果 <code>#if</code> 条件为假，当前条件为<code>真</code></td></tr><tr><td><code>#endif</code></td><td>结束一个 <code>#if……#else</code> 条件编译块</td></tr><tr><td><code>#error</code></td><td>当遇到标准错误时，输出错误消息</td></tr><tr><td><code>#pragma</code></td><td>使用标准化方法，向编译器发布特殊的命令到编译器中</td></tr></tbody></table>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token comment">// 所有的 MAX_ARRAY_LENGTH 替换为 20</span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name">MAX_ARRAY_LENGTH</span> <span class="token expression"><span class="token number">20</span></span></span>
</span><span class="code-line"><span class="token comment">// 系统库中获取 stdio.h</span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line"><span class="token comment">// 本地目录中获取 myheader.h</span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">"myheader.h"</span></span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">undef</span>  <span class="token expression">FILE_SIZE</span></span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name">FILE_SIZE</span> <span class="token expression"><span class="token number">42</span> </span><span class="token comment">// 取消已定义并定义为 42</span></span>
</span></code></pre>
</div></div></div><div class="wrap h3body-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="预定义宏"><a aria-hidden="true" tabindex="-1" href="#预定义宏"><span class="icon icon-link"></span></a>预定义宏</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->





























<table class="style-list"><thead><tr><th>宏</th><th>描述</th></tr></thead><tbody><tr><td><code>__DATE__</code></td><td>当前日期，一个以 "MMM DD YYYY" 格式表示的字符常量</td></tr><tr><td><code>__TIME__</code></td><td>当前时间，一个以 "HH:MM:SS" 格式表示的字符常量</td></tr><tr><td><code>__FILE__</code></td><td>这会包含当前文件名，一个字符串常量</td></tr><tr><td><code>__LINE__</code></td><td>这会包含当前行号，一个十进制常量</td></tr><tr><td><code>__STDC__</code></td><td>当编译器以 <code>ANSI</code> 标准编译时，则定义为 <code>1</code></td></tr></tbody></table>
<!--rehype:className=style-list-->
<p><code>ANSI C</code> 定义了许多宏，您可以使用这些宏，但是不能直接修改这些预定义的宏</p>
<h4 id="预定义宏示例"><a aria-hidden="true" tabindex="-1" href="#预定义宏示例"><span class="icon icon-link"></span></a>预定义宏示例</h4>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"File :%s\n"</span><span class="token punctuation">,</span> <span class="token constant">__FILE__</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Date :%s\n"</span><span class="token punctuation">,</span> <span class="token constant">__DATE__</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Time :%s\n"</span><span class="token punctuation">,</span> <span class="token constant">__TIME__</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Line :%d\n"</span><span class="token punctuation">,</span> <span class="token constant">__LINE__</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"ANSI :%d\n"</span><span class="token punctuation">,</span> __STDC__<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="宏延续运算符"><a aria-hidden="true" tabindex="-1" href="#宏延续运算符"><span class="icon icon-link"></span></a>宏延续运算符（\）</h3><div class="wrap-body">
<p>一个宏通常写在一个单行上。</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span>  <span class="token macro-name function">message_for</span><span class="token expression"><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span>  </span><span class="token punctuation">\</span>
</span></span><span class="code-line"><span class="token macro property">    <span class="token expression"><span class="token function">printf</span><span class="token punctuation">(</span>#a </span><span class="token string">" 和 "</span> <span class="token expression"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">b</span> </span></span><span class="token string">": 我们爱你！\n"</span><span class="token expression"><span class="token punctuation">)</span></span></span>
</span></code></pre>
<p>如果宏太长，一个单行容纳不下，则使用宏延续运算符 <code>\</code></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="字符串常量化运算符"><a aria-hidden="true" tabindex="-1" href="#字符串常量化运算符"><span class="icon icon-link"></span></a>字符串常量化运算符（#）</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span>  <span class="token macro-name function">message_for</span><span class="token expression"><span class="token punctuation">(</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span>  </span><span class="token punctuation">\</span>
</span></span><span class="code-line"><span class="token macro property">  <span class="token expression"><span class="token function">printf</span><span class="token punctuation">(</span>#a </span><span class="token string">" 和 "</span> <span class="token expression"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">b</span> </span></span><span class="token string">": 我们爱你！\n"</span><span class="token expression"><span class="token punctuation">)</span></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">message_for</span><span class="token punctuation">(</span>Carole<span class="token punctuation">,</span> Debra<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>当上面的代码被编译和执行时，它会产生下列结果：</p>
<pre><code class="code-highlight"><span class="code-line">Carole 和 Debra: 我们爱你！
</span></code></pre>
<p>需要把一个宏的参数转换为字符串常量时，使用字符串常量化运算符 <code>#</code></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="标记粘贴运算符"><a aria-hidden="true" tabindex="-1" href="#标记粘贴运算符"><span class="icon icon-link"></span></a>标记粘贴运算符（##）</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name function">tokenpaster</span><span class="token expression"><span class="token punctuation">(</span>n<span class="token punctuation">)</span> <span class="token function">printf</span> <span class="token punctuation">(</span></span><span class="token string">"token"</span> <span class="token expression"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">n</span> </span></span><span class="token string">" = %d"</span><span class="token expression"><span class="token punctuation">,</span> token</span><span class="token punctuation">##</span><span class="token expression">n<span class="token punctuation">)</span></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">int</span> token34 <span class="token operator">=</span> <span class="token number">40</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">tokenpaster</span><span class="token punctuation">(</span><span class="token number">34</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="defined-运算符"><a aria-hidden="true" tabindex="-1" href="#defined-运算符"><span class="icon icon-link"></span></a>defined() 运算符</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">if</span> <span class="token expression"><span class="token operator">!</span><span class="token function">defined</span> <span class="token punctuation">(</span>MESSAGE<span class="token punctuation">)</span></span></span>
</span><span class="code-line">   <span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name">MESSAGE</span> <span class="token string">"You wish!"</span></span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">endif</span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Here is the message: %s\n"</span><span class="token punctuation">,</span> MESSAGE<span class="token punctuation">)</span><span class="token punctuation">;</span>  
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="参数化的宏"><a aria-hidden="true" tabindex="-1" href="#参数化的宏"><span class="icon icon-link"></span></a>参数化的宏</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> <span class="token function">square</span><span class="token punctuation">(</span><span class="token keyword">int</span> x<span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">   <span class="token keyword">return</span> x <span class="token operator">*</span> x<span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>宏重写上面的代码，如下：</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name function">square</span><span class="token expression"><span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token operator">*</span> <span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>
</span></code></pre>
<p>宏名称和左圆括号之间不允许有空格</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name function">MAX</span><span class="token expression"><span class="token punctuation">(</span>x<span class="token punctuation">,</span>y<span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token operator">></span> <span class="token punctuation">(</span>y<span class="token punctuation">)</span> <span class="token operator">?</span> <span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token operator">:</span> <span class="token punctuation">(</span>y<span class="token punctuation">)</span><span class="token punctuation">)</span></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Max between 20 and 10 is %d\n"</span><span class="token punctuation">,</span> <span class="token function">MAX</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  
</span><span class="code-line">   <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="函数"><a aria-hidden="true" tabindex="-1" href="#函数"><span class="icon icon-link"></span></a>函数</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="函数声明和定义"><a aria-hidden="true" tabindex="-1" href="#函数声明和定义"><span class="icon icon-link"></span></a>函数声明和定义</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Hello World!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>函数由两部分组成</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">void</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">// 声明 declaration</span>
</span><span class="code-line">  <span class="token comment">// 函数体（要执行的代码）(definition)</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<hr>
<ul>
<li><code>Declaration</code> 声明函数名称、返回类型和参数 <em>(如果有)</em></li>
<li><code>Definition</code> 函数体 <em>(要执行的代码)</em></li>
</ul>
<hr>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token comment">// 函数声明</span>
</span><span class="code-line"><span class="token keyword">void</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 主要方法</span>
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// --> 调用函数</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token keyword">void</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span><span class="token comment">// 函数定义</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"晚上好！"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="调用函数"><a aria-hidden="true" tabindex="-1" href="#调用函数"><span class="icon icon-link"></span></a>调用函数</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token comment">// 创建函数</span>
</span><span class="code-line"><span class="token keyword">void</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"晚上好！"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 调用函数</span>
</span><span class="code-line">  <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 可以被多次调用</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token comment">// 输出 -> "晚上好！"</span>
</span><span class="code-line"><span class="token comment">// 输出 -> "晚上好！"</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="函数参数"><a aria-hidden="true" tabindex="-1" href="#函数参数"><span class="icon icon-link"></span></a>函数参数</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">void</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token keyword">char</span> name<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"Hello %s\n"</span><span class="token punctuation">,</span> name<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token string">"Liam"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token string">"Jenny"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token comment">// Hello Liam</span>
</span><span class="code-line"><span class="token comment">// Hello Jenny</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="多个参数"><a aria-hidden="true" tabindex="-1" href="#多个参数"><span class="icon icon-link"></span></a>多个参数</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">void</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token keyword">char</span> name<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token keyword">int</span> age<span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"你好 %s 你 %d 岁了。\n"</span><span class="token punctuation">,</span>name<span class="token punctuation">,</span>age<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token string">"Liam"</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token string">"Jenny"</span><span class="token punctuation">,</span> <span class="token number">14</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token comment">// 你好 Liam 你 3 岁了。</span>
</span><span class="code-line"><span class="token comment">// 你好 Jenny 你 14 岁了。</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="返回值"><a aria-hidden="true" tabindex="-1" href="#返回值"><span class="icon icon-link"></span></a>返回值</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token keyword">int</span> x<span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">5</span> <span class="token operator">+</span> x<span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"结果: %d"</span><span class="token punctuation">,</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token comment">// 输出 8 (5 + 3)</span>
</span></code></pre>
<p>两个参数</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token keyword">int</span> x<span class="token punctuation">,</span> <span class="token keyword">int</span> y<span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">return</span> x <span class="token operator">+</span> y<span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"结果: %d"</span><span class="token punctuation">,</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token comment">// 将结果存储在变量中</span>
</span><span class="code-line">  <span class="token keyword">int</span> result <span class="token operator">=</span> <span class="token function">myFunction</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"结果 = %d"</span><span class="token punctuation">,</span> result<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token comment">// 结果: 8 (5 + 3)</span>
</span><span class="code-line"><span class="token comment">// 结果 = 8 (5 + 3)</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="递归示例"><a aria-hidden="true" tabindex="-1" href="#递归示例"><span class="icon icon-link"></span></a>递归示例</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">int</span> <span class="token function">sum</span><span class="token punctuation">(</span><span class="token keyword">int</span> k<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">int</span> result <span class="token operator">=</span> <span class="token function">sum</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d"</span><span class="token punctuation">,</span> result<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">sum</span><span class="token punctuation">(</span><span class="token keyword">int</span> k<span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">if</span> <span class="token punctuation">(</span>k <span class="token operator">></span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token keyword">return</span> k <span class="token operator">+</span> <span class="token function">sum</span><span class="token punctuation">(</span>k <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="数学函数"><a aria-hidden="true" tabindex="-1" href="#数学函数"><span class="icon icon-link"></span></a>数学函数</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;math.h></span></span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%f"</span><span class="token punctuation">,</span> <span class="token function">sqrt</span><span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>   <span class="token comment">// 平方根</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%f"</span><span class="token punctuation">,</span> <span class="token function">ceil</span><span class="token punctuation">(</span><span class="token number">1.4</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// 四舍五入 (入)</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%f"</span><span class="token punctuation">,</span> <span class="token function">floor</span><span class="token punctuation">(</span><span class="token number">1.4</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 四舍五入 (舍)</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%f"</span><span class="token punctuation">,</span> <span class="token function">pow</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>  <span class="token comment">// x(4)的y(3)次方</span>
</span></code></pre>
<hr>
<ul class="cols-2">
<li><code>abs(x)</code> 绝对值</li>
<li><code>acos(x)</code> 反余弦值</li>
<li><code>asin(x)</code> 反正弦值</li>
<li><code>atan(x)</code> 反正切</li>
<li><code>cbrt(x)</code> 立方根</li>
<li><code>cos(x)</code> 余弦</li>
<li><code>exp(x)</code> Ex 的值</li>
<li><code>sin(x)</code> x 的正弦值</li>
<li><code>tan(x)</code> 角度的正切</li>
</ul>
<!--rehype:className=cols-2-->
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="structures-结构"><a aria-hidden="true" tabindex="-1" href="#structures-结构"><span class="icon icon-link"></span></a>Structures 结构</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="创建结构"><a aria-hidden="true" tabindex="-1" href="#创建结构"><span class="icon icon-link"></span></a>创建结构</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">struct</span> <span class="token class-name">MyStructure</span> <span class="token punctuation">{</span>  <span class="token comment">// 结构声明</span>
</span><span class="code-line">  <span class="token keyword">int</span> myNum<span class="token punctuation">;</span>     <span class="token comment">// 成员（int 变量）</span>
</span><span class="code-line">  <span class="token keyword">char</span> myLetter<span class="token punctuation">;</span> <span class="token comment">// 成员（char 变量）</span>
</span><span class="code-line"><span class="token punctuation">}</span><span class="token punctuation">;</span> <span class="token comment">// 用分号结束结构</span>
</span></code></pre>
<p>创建一个名为 <code>s1</code> 的结构变量</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">struct</span> <span class="token class-name">myStructure</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">int</span> myNum<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">char</span> myLetter<span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line highlight-line">  <span class="token keyword">struct</span> <span class="token class-name">myStructure</span> s1<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="结构中的字符串"><a aria-hidden="true" tabindex="-1" href="#结构中的字符串"><span class="icon icon-link"></span></a>结构中的字符串</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">struct</span> <span class="token class-name">myStructure</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">int</span> myNum<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">char</span> myLetter<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">char</span> myString<span class="token punctuation">[</span><span class="token number">30</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment">// String</span>
</span><span class="code-line"><span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">struct</span> <span class="token class-name">myStructure</span> s1<span class="token punctuation">;</span>
</span><span class="code-line highlight-line">  <span class="token function">strcpy</span><span class="token punctuation">(</span>s1<span class="token punctuation">.</span>myString<span class="token punctuation">,</span> <span class="token string">"Some text"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token comment">// 打印值</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"我字符串: %s"</span><span class="token punctuation">,</span> s1<span class="token punctuation">.</span>myString<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>使用 <code>strcpy</code> 函数为字符串赋值</p>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="访问结构成员"><a aria-hidden="true" tabindex="-1" href="#访问结构成员"><span class="icon icon-link"></span></a>访问结构成员</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token comment">// 创建一个名为 myStructure 的结构</span>
</span><span class="code-line"><span class="token keyword">struct</span> <span class="token class-name">myStructure</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token keyword">int</span> myNum<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">char</span> myLetter<span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">int</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token comment">// 创建一个名为 s1 的 myStructure 结构变量</span>
</span><span class="code-line">  <span class="token keyword">struct</span> <span class="token class-name">myStructure</span> s1<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token comment">// 为 s1 的成员赋值</span>
</span><span class="code-line highlight-line">  s1<span class="token punctuation">.</span>myNum <span class="token operator">=</span> <span class="token number">13</span><span class="token punctuation">;</span>
</span><span class="code-line highlight-line">  s1<span class="token punctuation">.</span>myLetter <span class="token operator">=</span> <span class="token char">'B'</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line">  <span class="token comment">// 创建一个名为 s2 的 myStructure 结构变量</span>
</span><span class="code-line">  <span class="token comment">// 并为其赋值</span>
</span><span class="code-line highlight-line">  <span class="token keyword">struct</span> <span class="token class-name">myStructure</span> s2 <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token number">13</span><span class="token punctuation">,</span> <span class="token char">'B'</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token comment">// 打印值</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"My number: %d\n"</span><span class="token punctuation">,</span> s1<span class="token punctuation">.</span>myNum<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"My letter: %c\n"</span><span class="token punctuation">,</span> s1<span class="token punctuation">.</span>myLetter<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>创建不同的结构变量</p>
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">struct</span> <span class="token class-name">myStructure</span> s1<span class="token punctuation">;</span>
</span><span class="code-line"><span class="token keyword">struct</span> <span class="token class-name">myStructure</span> s2<span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 为不同的结构变量赋值</span>
</span><span class="code-line">s1<span class="token punctuation">.</span>myNum <span class="token operator">=</span> <span class="token number">13</span><span class="token punctuation">;</span>
</span><span class="code-line">s1<span class="token punctuation">.</span>myLetter <span class="token operator">=</span> <span class="token char">'B'</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line">s2<span class="token punctuation">.</span>myNum <span class="token operator">=</span> <span class="token number">20</span><span class="token punctuation">;</span>
</span><span class="code-line">s2<span class="token punctuation">.</span>myLetter <span class="token operator">=</span> <span class="token char">'C'</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="复制结构"><a aria-hidden="true" tabindex="-1" href="#复制结构"><span class="icon icon-link"></span></a>复制结构</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token keyword">struct</span> <span class="token class-name">myStructure</span> s1 <span class="token operator">=</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token number">13</span><span class="token punctuation">,</span> <span class="token char">'B'</span><span class="token punctuation">,</span> <span class="token string">"Some text"</span>
</span><span class="code-line"><span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">struct</span> <span class="token class-name">myStructure</span> s2<span class="token punctuation">;</span>
</span><span class="code-line highlight-line">s2 <span class="token operator">=</span> s1<span class="token punctuation">;</span>
</span></code></pre>
<p>示例中，将 <code>s1</code> 的值复制到 <code>s2</code></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="修改值"><a aria-hidden="true" tabindex="-1" href="#修改值"><span class="icon icon-link"></span></a>修改值</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token comment">// 创建一个结构变量并为其赋值</span>
</span><span class="code-line"><span class="token keyword">struct</span> <span class="token class-name">myStructure</span> s1 <span class="token operator">=</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token number">13</span><span class="token punctuation">,</span> <span class="token char">'B'</span>
</span><span class="code-line"><span class="token punctuation">}</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 修改值</span>
</span><span class="code-line highlight-line">s1<span class="token punctuation">.</span>myNum <span class="token operator">=</span> <span class="token number">30</span><span class="token punctuation">;</span>
</span><span class="code-line highlight-line">s1<span class="token punctuation">.</span>myLetter <span class="token operator">=</span> <span class="token char">'C'</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token comment">// 打印值</span>
</span><span class="code-line"><span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%d %c %s"</span><span class="token punctuation">,</span>
</span><span class="code-line">    s1<span class="token punctuation">.</span>myNum<span class="token punctuation">,</span>
</span><span class="code-line">    s1<span class="token punctuation">.</span>myLetter<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="文件处理"><a aria-hidden="true" tabindex="-1" href="#文件处理"><span class="icon icon-link"></span></a>文件处理</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="文件处理函数"><a aria-hidden="true" tabindex="-1" href="#文件处理函数"><span class="icon icon-link"></span></a>文件处理函数</h3><div class="wrap-body">





















































<table><thead><tr><th>函数</th><th>描述 Description</th></tr></thead><tbody><tr><td><code>fopen()</code></td><td><code>打开</code>新文件或现有文件</td></tr><tr><td><code>fprintf()</code></td><td>将数据<code>写入</code>文件</td></tr><tr><td><code>fscanf()</code></td><td>从文件中<code>读取</code>数据</td></tr><tr><td><code>fputc()</code></td><td>将一个字符<code>写入</code>文件</td></tr><tr><td><code>fgetc()</code></td><td>从文件中<code>读取</code>一个字符</td></tr><tr><td><code>fclose()</code></td><td><code>关闭</code>文件</td></tr><tr><td><code>fseek()</code></td><td>将文件指针设置到<code>给定位置</code></td></tr><tr><td><code>fputw()</code></td><td>将整数<code>写入</code>文件</td></tr><tr><td><code>fgetw()</code></td><td>从文件中<code>读取</code>一个整数</td></tr><tr><td><code>ftell()</code></td><td>返回当前<code>位置</code></td></tr><tr><td><code>rewind()</code></td><td>将文件指针设置为文件的开头</td></tr></tbody></table>
<p>C 库中有许多函数可以<code>打开</code>/<code>读取</code>/<code>写入</code>/<code>搜索</code>和<code>关闭</code>文件</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="打开模式参数"><a aria-hidden="true" tabindex="-1" href="#打开模式参数"><span class="icon icon-link"></span></a>打开模式参数</h3><div class="wrap-body">

























































<table><thead><tr><th>模式 Mode</th><th>描述 Description</th></tr></thead><tbody><tr><td><code>r</code></td><td>以<code>读取</code>模式打开一个文本文件，允许读取文件</td></tr><tr><td><code>w</code></td><td>以<code>写</code>模式打开一个文本文件，允许写入文件</td></tr><tr><td><code>a</code></td><td>以<code>追加</code>模式打开一个文本文件<br>如果文件不存在，则会创建一个新文件</td></tr><tr><td><code>r+</code></td><td>以<code>读写</code>模式打开一个文本文件，允许读写文件</td></tr><tr><td><code>w+</code></td><td>以<code>读写</code>模式打开一个文本文件，允许读写文件</td></tr><tr><td><code>a+</code></td><td>以<code>读写</code>模式打开一个文本文件，允许读写文件</td></tr><tr><td><code>rb</code></td><td>以<code>读取</code>模式打开二进制文件</td></tr><tr><td><code>wb</code></td><td>以<code>写入</code>模式打开二进制文件</td></tr><tr><td><code>ab</code></td><td>以<code>追加</code>模式打开二进制文件</td></tr><tr><td><code>rb+</code></td><td>以<code>读写</code>模式打开二进制文件</td></tr><tr><td><code>wb+</code></td><td>以<code>读写</code>模式打开二进制文件</td></tr><tr><td><code>ab+</code></td><td>以<code>读写</code>模式打开二进制文件</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="打开文件fopen"><a aria-hidden="true" tabindex="-1" href="#打开文件fopen"><span class="icon icon-link"></span></a>打开文件：fopen()</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  FILE <span class="token operator">*</span>fp<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">char</span> ch<span class="token punctuation">;</span>
</span><span class="code-line highlight-line">  fp <span class="token operator">=</span> <span class="token function">fopen</span><span class="token punctuation">(</span><span class="token string">"file_handle.c"</span><span class="token punctuation">,</span> <span class="token string">"r"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line">  <span class="token keyword">while</span> <span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">    ch <span class="token operator">=</span> <span class="token function">fgetc</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">    <span class="token keyword">if</span> <span class="token punctuation">(</span>ch <span class="token operator">==</span> <span class="token constant">EOF</span><span class="token punctuation">)</span>
</span><span class="code-line">    <span class="token keyword">break</span><span class="token punctuation">;</span>
</span><span class="code-line">    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%c"</span><span class="token punctuation">,</span> ch<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token function">fclose</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>对文件执行所有操作后，必须关闭 <code>fclose()</code> 该文件</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="写入文件fprintf"><a aria-hidden="true" tabindex="-1" href="#写入文件fprintf"><span class="icon icon-link"></span></a>写入文件：fprintf()</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  FILE <span class="token operator">*</span>fp<span class="token punctuation">;</span>
</span><span class="code-line">  fp <span class="token operator">=</span> <span class="token function">fopen</span><span class="token punctuation">(</span><span class="token string">"file.txt"</span><span class="token punctuation">,</span> <span class="token string">"w"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 打开文件</span>
</span><span class="code-line">  <span class="token comment">// 将数据写入文件</span>
</span><span class="code-line highlight-line">  <span class="token function">fprintf</span><span class="token punctuation">(</span>fp<span class="token punctuation">,</span> <span class="token string">"fprintf 的 Hello 文件..\n"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">fclose</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 关闭文件  </span>
</span><span class="code-line"><span class="token punctuation">}</span>  
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="读取文件fscanf"><a aria-hidden="true" tabindex="-1" href="#读取文件fscanf"><span class="icon icon-link"></span></a>读取文件：fscanf()</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span>  </span>
</span><span class="code-line"><span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
</span><span class="code-line">  FILE <span class="token operator">*</span>fp<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">char</span> buff<span class="token punctuation">[</span><span class="token number">255</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token comment">// 创建char数组存储文件数据</span>
</span><span class="code-line">  fp <span class="token operator">=</span> <span class="token function">fopen</span><span class="token punctuation">(</span><span class="token string">"file.txt"</span><span class="token punctuation">,</span> <span class="token string">"r"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line highlight-line">  <span class="token keyword">while</span><span class="token punctuation">(</span><span class="token function">fscanf</span><span class="token punctuation">(</span>fp<span class="token punctuation">,</span> <span class="token string">"%s"</span><span class="token punctuation">,</span> buff<span class="token punctuation">)</span><span class="token operator">!=</span><span class="token constant">EOF</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%s "</span><span class="token punctuation">,</span> buff<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token function">fclose</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="写入文件fputc"><a aria-hidden="true" tabindex="-1" href="#写入文件fputc"><span class="icon icon-link"></span></a>写入文件：fputc()</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
</span><span class="code-line">  FILE <span class="token operator">*</span>fp<span class="token punctuation">;</span>
</span><span class="code-line">  fp <span class="token operator">=</span> <span class="token function">fopen</span><span class="token punctuation">(</span><span class="token string">"file1.txt"</span><span class="token punctuation">,</span> <span class="token string">"w"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 打开文件</span>
</span><span class="code-line highlight-line">  <span class="token function">fputc</span><span class="token punctuation">(</span><span class="token char">'a'</span><span class="token punctuation">,</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 将单个字符写入文件</span>
</span><span class="code-line">  <span class="token function">fclose</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span>    <span class="token comment">// 关闭文件</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="读取文件fgetc"><a aria-hidden="true" tabindex="-1" href="#读取文件fgetc"><span class="icon icon-link"></span></a>读取文件：fgetc()</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&#x3C;conio.h></span></span>
</span><span class="code-line"><span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  FILE <span class="token operator">*</span>fp<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">char</span> c<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">clrscr</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  fp<span class="token operator">=</span><span class="token function">fopen</span><span class="token punctuation">(</span><span class="token string">"myfile.txt"</span><span class="token punctuation">,</span> <span class="token string">"r"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line highlight-line">  <span class="token keyword">while</span><span class="token punctuation">(</span><span class="token punctuation">(</span>c<span class="token operator">=</span><span class="token function">fgetc</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token operator">!=</span><span class="token constant">EOF</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%c"</span><span class="token punctuation">,</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token function">fclose</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">getch</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="写入文件fputs"><a aria-hidden="true" tabindex="-1" href="#写入文件fputs"><span class="icon icon-link"></span></a>写入文件：fputs()</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&#x3C;conio.h></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
</span><span class="code-line">  FILE <span class="token operator">*</span>fp<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">clrscr</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  fp <span class="token operator">=</span> <span class="token function">fopen</span><span class="token punctuation">(</span><span class="token string">"myfile2.txt"</span><span class="token punctuation">,</span><span class="token string">"w"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line highlight-line">  <span class="token function">fputs</span><span class="token punctuation">(</span><span class="token string">"hello c programming"</span><span class="token punctuation">,</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">fclose</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">getch</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="读取文件fgets"><a aria-hidden="true" tabindex="-1" href="#读取文件fgets"><span class="icon icon-link"></span></a>读取文件：fgets()</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&#x3C;conio.h></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
</span><span class="code-line">  FILE <span class="token operator">*</span>fp<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">char</span> text<span class="token punctuation">[</span><span class="token number">300</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">clrscr</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line">  fp<span class="token operator">=</span><span class="token function">fopen</span><span class="token punctuation">(</span><span class="token string">"myfile2.txt"</span><span class="token punctuation">,</span> <span class="token string">"r"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line highlight-line">  <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%s"</span><span class="token punctuation">,</span> <span class="token function">fgets</span><span class="token punctuation">(</span>text<span class="token punctuation">,</span> <span class="token number">200</span><span class="token punctuation">,</span> fp<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">fclose</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">getch</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="fseek"><a aria-hidden="true" tabindex="-1" href="#fseek"><span class="icon icon-link"></span></a>fseek()</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line"><span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
</span><span class="code-line">  FILE <span class="token operator">*</span>fp<span class="token punctuation">;</span>
</span><span class="code-line">  fp <span class="token operator">=</span> <span class="token function">fopen</span><span class="token punctuation">(</span><span class="token string">"myfile.txt"</span><span class="token punctuation">,</span><span class="token string">"w+"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">fputs</span><span class="token punctuation">(</span><span class="token string">"This is Book"</span><span class="token punctuation">,</span> fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line">  <span class="token comment">// 将文件指针设置到给定位置</span>
</span><span class="code-line highlight-line">  <span class="token function">fseek</span><span class="token punctuation">(</span>fp<span class="token punctuation">,</span> <span class="token number">7</span><span class="token punctuation">,</span> <span class="token constant">SEEK_SET</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">fputs</span><span class="token punctuation">(</span><span class="token string">"Kenny Wong"</span><span class="token punctuation">,</span> fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">fclose</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>将文件指针设置到给定位置</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="rewind"><a aria-hidden="true" tabindex="-1" href="#rewind"><span class="icon icon-link"></span></a>rewind()</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span><span class="token string">&#x3C;conio.h></span></span>
</span><span class="code-line"><span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
</span><span class="code-line">  FILE <span class="token operator">*</span>fp<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">char</span> c<span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">clrscr</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  fp<span class="token operator">=</span><span class="token function">fopen</span><span class="token punctuation">(</span><span class="token string">"file.txt"</span><span class="token punctuation">,</span> <span class="token string">"r"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token keyword">while</span><span class="token punctuation">(</span><span class="token punctuation">(</span>c<span class="token operator">=</span><span class="token function">fgetc</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token constant">EOF</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%c"</span><span class="token punctuation">,</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line highlight-line">  <span class="token function">rewind</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 将文件指针移动到文件的开头</span>
</span><span class="code-line">  <span class="token keyword">while</span><span class="token punctuation">(</span><span class="token punctuation">(</span>c<span class="token operator">=</span><span class="token function">fgetc</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token constant">EOF</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"%c"</span><span class="token punctuation">,</span> c<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token function">fclose</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">  <span class="token function">getch</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token comment">// 输出</span>
</span><span class="code-line"><span class="token comment">// Hello World!Hello World!</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="ftell"><a aria-hidden="true" tabindex="-1" href="#ftell"><span class="icon icon-link"></span></a>ftell()</h3><div class="wrap-body">
<pre class="language-c"><code class="language-c code-highlight"><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;stdio.h></span></span>
</span><span class="code-line"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&#x3C;conio.h></span></span>
</span><span class="code-line">
</span><span class="code-line"><span class="token keyword">void</span> <span class="token function">main</span> <span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
</span><span class="code-line">   FILE <span class="token operator">*</span>fp<span class="token punctuation">;</span>
</span><span class="code-line">   <span class="token keyword">int</span> length<span class="token punctuation">;</span>
</span><span class="code-line">   <span class="token function">clrscr</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">   fp <span class="token operator">=</span> <span class="token function">fopen</span><span class="token punctuation">(</span><span class="token string">"file.txt"</span><span class="token punctuation">,</span> <span class="token string">"r"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">   <span class="token function">fseek</span><span class="token punctuation">(</span>fp<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token constant">SEEK_END</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">
</span><span class="code-line highlight-line">   length <span class="token operator">=</span> <span class="token function">ftell</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 返回当前位置</span>
</span><span class="code-line">
</span><span class="code-line">   <span class="token function">fclose</span><span class="token punctuation">(</span>fp<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">   <span class="token function">printf</span><span class="token punctuation">(</span><span class="token string">"文件大小: %d bytes"</span><span class="token punctuation">,</span> length<span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line">   <span class="token function">getch</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span><span class="code-line"><span class="token comment">// 输出</span>
</span><span class="code-line"><span class="token comment">// 文件大小: 18 bytes</span>
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="杂项"><a aria-hidden="true" tabindex="-1" href="#杂项"><span class="icon icon-link"></span></a>杂项</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="docker-运行环境"><a aria-hidden="true" tabindex="-1" href="#docker-运行环境"><span class="icon icon-link"></span></a>Docker 运行环境</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<ul class="style-timeline">
<li>
<p>安装 <a href="./docker.html"><code>Docker</code></a></p>
</li>
<li>
<p>创建 <a href="./dockerfile.html"><code>Dockerfile</code></a> 文件</p>
<pre class="language-dockerfile"><code class="language-dockerfile code-highlight"><span class="code-line"><span class="token instruction"><span class="token keyword">FROM</span> alpine:3.14</span>
</span><span class="code-line"><span class="token instruction"><span class="token keyword">RUN</span> apk add --no-cache gcc musl-dev</span>
</span><span class="code-line"><span class="token instruction"><span class="token keyword">RUN</span> apk add --no-cache g++</span>
</span></code></pre>
</li>
<li>
<p>生成本地 myalpine 镜像</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token function">docker</span> build <span class="token parameter variable">-t</span> myalpine <span class="token builtin class-name">.</span>
</span></code></pre>
</li>
<li>
<p>运行映像，把当前路径 <code>($PWD)</code> 映射至容器的 <code>/test</code> 目录，用 <code>gcc</code> 编译程序，<code>exit</code>返回</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line"><span class="token function">docker</span> run <span class="token parameter variable">-it</span> <span class="token parameter variable">-v</span> <span class="token environment constant">$PWD</span>:/test myalpine
</span><span class="code-line">root@b1a38bd7107a:/<span class="token comment"># cd test</span>
</span><span class="code-line">root@b1a38bd7107a:/test<span class="token comment"># gcc -o hello hello.c</span>
</span><span class="code-line">Hello World
</span><span class="code-line">root@b1a38bd7107a:/test<span class="token comment"># exit</span>
</span><span class="code-line"><span class="token builtin class-name">exit</span>
</span></code></pre>
</li>
</ul>
<!--rehype:className=style-timeline-->
</div></div></div></div></div><div class="wrap h2body-not-exist"><div class="wrap-header h2wrap"><h2 id="另见"><a aria-hidden="true" tabindex="-1" href="#另见"><span class="icon icon-link"></span></a>另见</h2><div class="wrap-body">
<ul>
<li><a href="https://jaywcjlove.github.io/c-tutorial">C 教程</a> <em>(jaywcjlove.github.io)</em></li>
</ul>
</div></div><div class="h2wrap-body"></div></div></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 Kenny Wang.</footer></footer><script src="../data.js" defer></script><script src="../js/fuse.min.js" defer></script><script src="../js/main.js" defer></script><div id="mysearch"><div class="mysearch-box"><div class="mysearch-input"><div><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><input id="mysearch-input" type="search" placeholder="搜索" autocomplete="off"><div class="mysearch-clear"></div></div><button id="mysearch-close" type="button">搜索</button></div><div class="mysearch-result"><div id="mysearch-menu"></div><div id="mysearch-content"></div></div></div></div></body>
</html>
